export const LoadingStatus = {
  NONE: 'NONE',
  PENDING: 'PENDING',
  DONE: 'DONE',
  ERROR: 'ERROR',
};

export const FormStatus = {
  WRITE: 'WRITE',
  VERIFY_PASSED: 'VERIFY_PASSED',
  PENDING: 'PENDING',
  SUCCESS: 'SUCCESS',
  FAIL: 'FAIL',
};

const initialState = {
  loading: LoadingStatus.NONE,
  formStatus: FormStatus.WRITE,
  message: null,
};

export const AppActions = {
  APP_STATE_UPDATE: 'app_state_update',
  APP_STATE_RESET: 'app_state_reset',
};

export function updateAppState(payload) {
  return {
    type: AppActions.APP_STATE_UPDATE,
    payload,
  };
}

export function resetAppState() {
  return {
    type: AppActions.APP_STATE_RESET,
  };
}

export default function appState(state = initialState, action) {
  switch (action.type) {
    case AppActions.APP_STATE_UPDATE:
      return {...state, ...action.payload};
    case AppActions.APP_STATE_RESET:
      return initialState;
    default:
      return state;
  }
}
